package com.wm.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wm.dao.UserDao;
import com.wm.dao.UserPermDao;
import com.wm.entity.RbacUser;
import com.wm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private UserPermDao userPermDao;


    @Override
    public RbacUser login(String account) {

        RbacUser user = userDao.getByAccount(account);
        return user;
    }

    @Override
    public void add(RbacUser user, int[] permIds) {
        userDao.insert(user);

        for (int permId: permIds) {
            userPermDao.add(user.getId(),permId);
        }
    }

    @Override
    public List<RbacUser> getAll() {
        return null;
    }

    @Override
    public PageInfo<RbacUser> getByCondition(int pageNum, RbacUser rbacUser) {
        PageHelper.startPage(pageNum,2);
        List<RbacUser> rbacUsers = userDao.getAll();

        return new PageInfo<>(rbacUsers);
    }
}
